//
//  MainViewController.m
//  song-git
//
//  Created by song on 16/2/20.
//  Copyright © 2016年 song. All rights reserved.
//

#import "MainViewController.h"
#import "TitleScrollViewController.h"
#import "LanguageSearchView.h"
#import "ProjectsTableViewController.h"

@interface MainViewController () <UITabBarControllerDelegate ,UITabBarDelegate>

@property (nonatomic, strong) NSArray *titles;
@property (nonatomic, strong) NSArray *images;
@property (nonatomic, strong) NSArray *selectedImages;

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _titles = @[@"项目", @"发现", @"我的"];
    _images = @[@"projects", @"discover", @"mine"];
    _selectedImages = @[@"projects_selected", @"discover_selected", @"mine_selected"];
    
    
    
    TitleScrollViewController *titleScrollCtl = [[TitleScrollViewController alloc] initWithTitle:@"项目" andSubTitles:@[@"推荐",@"热门",@"最近更新"]                     andSubControllers:@[ [[ProjectsTableViewController alloc] initWithProjectsType:ProjectsTypeFeatured ],[[ProjectsTableViewController alloc] initWithProjectsType:ProjectsTypePopular],[[ProjectsTableViewController alloc] initWithProjectsType:ProjectsTypeLatest] ]  andUnderTarbar:YES andUserPortrait:NO];
    UINavigationController *projectNav =[[UINavigationController alloc] initWithRootViewController:titleScrollCtl];
    
    
    LanguageSearchView *searchView =[LanguageSearchView new];
    UINavigationController *languagetNav =[[UINavigationController alloc] initWithRootViewController:searchView];
    
    TitleScrollViewController *ownDetailsView = [[TitleScrollViewController alloc] initWithTitle:@"我的" andSubTitles:@[@"动态",@"项目",@"Star",@"Watch"]  andSubControllers:@[[[ProjectsTableViewController alloc] init],[[ProjectsTableViewController alloc] init],[[ProjectsTableViewController alloc] init],[[ProjectsTableViewController alloc] init]] andUnderTarbar:YES andUserPortrait:NO];
    UINavigationController *ownNav =[[UINavigationController alloc] initWithRootViewController:ownDetailsView];
    
    self.viewControllers = @[projectNav,languagetNav,ownNav];
    [self.tabBar.items enumerateObjectsUsingBlock:^(UITabBarItem * _Nonnull item, NSUInteger idx, BOOL * _Nonnull stop) {
        [item setTitle:_titles[idx]];
        [item setImage:[[UIImage imageNamed:_images[idx]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        [item setSelectedImage:[[UIImage imageNamed:_selectedImages[idx]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    }];
    self.delegate  = self;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    return  YES;
}


@end
